import type { ResponseData } from "@/types/common/response";
import type { RuleQuery, RuleVO, RuleForm } from "@/types/attendance/rule";
import { http } from "@/utils/http";

/**
 * 查询考勤规则列表
 */
export function getRuleList(query: RuleQuery): Promise<
  ResponseData<{
    rows: RuleVO[];
    total: number;
  }>
> {
  return http.request("get", "/attendance/rule/list", { params: query });
}

/**
 * 获取考勤规则详情
 */
export function getRule(ruleId: number): Promise<ResponseData<RuleVO>> {
  return http.request("get", `/attendance/rule/${ruleId}`);
}

/**
 * 新增考勤规则
 */
export function addRule(data: RuleForm): Promise<ResponseData<void>> {
  return http.request("post", "/attendance/rule", { data });
}

/**
 * 修改考勤规则
 */
export function updateRule(data: RuleForm): Promise<ResponseData<void>> {
  return http.request("put", "/attendance/rule", { data });
}

/**
 * 删除考勤规则
 */
export function deleteRule(ruleId: number): Promise<ResponseData<void>> {
  return http.request("delete", `/attendance/rule/${ruleId}`);
}

/**
 * 更新考勤规则状态
 */
export function updateRuleStatus(ruleId: number, status: string): Promise<ResponseData<void>> {
  return http.request("put", `/attendance/rule/status/${ruleId}`, {
    data: { status }
  });
}

/**
 * 获取部门考勤规则
 */
export function getDepartmentRule(deptId: number): Promise<ResponseData<RuleVO>> {
  return http.request("get", `/attendance/rule/department/${deptId}`);
}

/**
 * 设置部门考勤规则
 */
export function setDepartmentRule(deptId: number, ruleId: number): Promise<ResponseData<void>> {
  return http.request("put", `/attendance/rule/department/${deptId}`, {
    data: { ruleId }
  });
}

/**
 * 获取人员考勤规则
 */
export function getPersonnelRule(personnelId: number): Promise<ResponseData<RuleVO>> {
  return http.request("get", `/attendance/rule/personnel/${personnelId}`);
}

/**
 * 设置人员考勤规则
 */
export function setPersonnelRule(personnelId: number, ruleId: number): Promise<ResponseData<void>> {
  return http.request("put", `/attendance/rule/personnel/${personnelId}`, {
    data: { ruleId }
  });
}

/**
 * 批量设置部门考勤规则
 */
export function batchSetDepartmentRule(
  deptIds: number[],
  ruleId: number
): Promise<ResponseData<void>> {
  return http.request("put", "/attendance/rule/department/batch", {
    data: { deptIds, ruleId }
  });
}

/**
 * 批量设置人员考勤规则
 */
export function batchSetPersonnelRule(
  personnelIds: number[],
  ruleId: number
): Promise<ResponseData<void>> {
  return http.request("put", "/attendance/rule/personnel/batch", {
    data: { personnelIds, ruleId }
  });
}
